# balFun :: function that returns balance over covariates in continuous matching

balFun=function(mMat=bMat,outs=outs,tr=tr){
	
	i_lefts=which(tr[outs[,1]]>tr[outs[,2]])
	i_right=which(tr[outs[,1]]<=tr[outs[,2]])
	lefts=c(outs[i_lefts,1],outs[i_right,2])
	right=c(outs[i_lefts,2],outs[i_right,1])	
	
	bals=matrix(NA,ncol(mMat),2)
	
	for(j in 1:ncol(mMat)){
		bals[j,1]=t.test(mMat[lefts,j],mMat[right,j])$p.value
		bals[j,2]=ks.test(jitter(mMat[lefts,j]),jitter(mMat[right,j]))$p.value
	}
      
	bals=c(length(which(bals>.1))/length(bals))
	print(bals)
	if(bals<.1){
		return(c(-1e100,-1e100))
	}else{
		return(bals)
	}
}
#end